E:/E+I/Informatik/Projekte/FH/n-Damen Problem/calculate.c

Go to the documentation of this file.
00001 
00009 #include "ndame.h"
00010 
00026 void calculate(struct data*d1,int irow)
00027 {
00028     int ii=0;
00029     static int is;
00030     char chscan;
00031     
00032     if(!irow)
00033     {
00034        is=0;                                          //exit clear singlestep for new calculation
00035     }                                                 
00036     if(is)
00037     {
00038         return;                                       //exit singlestep
00039     }
00040     
00041     while(irow<d1->iblength)
00042     {
00043         if(ii<d1->iblength)
00044         {
00045             if(!(attack(d1,irow,ii)))                 //checks if queen is attacked
00046             {
00047                 d1->iboard[irow][ii]=1;               //set queen
00048                 calculate(d1,irow+1);                 //recursion
00049                 d1->iboard[irow][ii]=0;               //clear queen
00050                 
00051                 if(d1->m1==manual)                    //chessboard refresh
00052                 {
00053                     if((irow+ii)%2)                   //regenerate board
00054                     {
00055                         gotoxy(X_POS+ii,Y_POS+irow);
00056                         printf("%c",BOARD_PART_1);
00057                     }
00058                     else
00059                     {
00060                         gotoxy(X_POS+ii,Y_POS+irow);
00061                         printf("%c",BOARD_PART_2);
00062                     }
00063                 }
00064                 ii++;                                 //increment column
00065             }
00066             else
00067             {
00068                 ii++;                                 //increment culumn
00069             }
00070         }
00071         else
00072         {
00073             return;
00074         }
00075     }
00076     
00077     d1->isolutions++;                                 //increment solution
00078     state(d1,5);                                      //refresh status of solutions
00079         
00080     if(d1->isave)                                     //save solution on HDD(*dll file)
00081     {
00082         ssolution(d1->iboard,d1->iblength,d1->isolutions,&d1->iauthor,d1->cfilename);
00083     }
00084     
00085     if(d1->m1==manual)                                //Singlestep
00086     {
00087         psolution(d1);                                //print solution on screen
00088         gotoxy(12,10);                                
00089         printf("(Any Key) - Go on");                  
00090         gotoxy(9,12);
00091         printf("(S) - Exit manual Step");
00092             
00093         chscan=getch();
00094         if((chscan=='e')||(chscan=='s'))
00095         {
00096             if(chscan=='e')
00097             {
00098                 exit(1);
00099             }
00100             is=1;                                     //when is=1 all calculate functions will closed
00101         }          
00102     }
00103     else
00104     {
00105         if(kbhit())                                   //when you press keyboard function 
00106         {                                             //checks if exit or not
00107             chscan=getch();
00108             if(chscan=='e')
00109             {
00110                 exit(1);
00111             }
00112         }             
00113     }    
00114 }

Generated on Sun Dec 18 19:26:13 2005 for n-Queens Problem by  doxygen 1.4.5